package com.aurora.source.base;

import android.content.Intent;

/**
 * Base Lazy Fragment
 * <p>
 * Created by Lance
 * 2018/7/6.
 */
public abstract class BaseLazyFragment<T extends BasePresenter> extends BaseFragment<T> {

    public boolean isDataLoaded;

    public abstract void doLazyBusiness();

    public abstract void invisibleBusiness();

    @Override
    public void setUserVisibleHint(boolean isVisibleToUser) {
        try {
            super.setUserVisibleHint(isVisibleToUser);
            if (mContentView != null) {
                if (isVisibleToUser) {
                    if (!isDataLoaded) {
                        isDataLoaded = true;
                        doLazyBusiness();
                    }
                } else {
                    invisibleBusiness();
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void doBusiness() {
        try {
            if (getUserVisibleHint()) {
                doLazyBusiness();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
    public void startActivity(Class clazz){
        try {
            Intent intent=new Intent(getActivity(),clazz);
            getActivity().startActivity(intent);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


}
